package com.tm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tm.dto.DishDTO;
import com.tm.entity.DishEntity;

import com.tm.mapper.DishMapper;
import com.tm.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author huangp
 * @create 2023-04-05 10:35
 */
@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, DishEntity> implements DishService {

    @Autowired
    private DishMapper dishMapper;

    @Override
    public Page<DishEntity> pageList(Integer page, Integer pageSize, DishDTO dishDTO) {

        Page<DishEntity> page1 = new Page<>(page,pageSize);
        QueryWrapper<DishEntity> queryWrapper = new QueryWrapper<DishEntity>();
        queryWrapper.eq("d.is_deleted",0);
        queryWrapper.eq("c.type",1);
        queryWrapper.like(StringUtils.isNotBlank(dishDTO.getName()),"d.name",dishDTO.getName());
        Page<DishEntity> page2 = dishMapper.pageList(page1,queryWrapper);
        return page2;

    }


    @Override
    public Boolean addCategory(DishEntity dishEntity) {
        return dishMapper.insert(dishEntity) > 0;
    }

    @Override
    public Boolean updateIds(List<Long> ids) {
        return dishMapper.selectIds(ids) > 0;
    }
}
